// stores/userInfo.js
import { defineStore } from 'pinia'




export const useGoodsStore = defineStore('GoodsStore', {

  // 持久化插件的配置
  persist:{
    key:'GoodsStore',
    storage:sessionStorage,
    pick:["name","price"],
    debug:true
  },


    //用于定义存储数据的位置 
  state: () => {
    return { 
        name:'魔方法式软面包111111',
        price: 19.8,
        count:1
    }
  },


  getters:{
    amount():number{
       return Number((this.count * this.price).toFixed(2))
      //  return this.count * this.price
    }
  },

  //修改数据
  actions:{
     plusCount(){
            this.count++
      },
      increament(num:number){
        this.count += num;
      },

      subCount(){
          if( this.count == 1){
              return
          }
          this.count--
      }
  }



  
})